10. Lesson Review
In this lesson we learned…
How does spacial audio work?
Spacial audio allows us to simulate how we hear things in the real world. As we get closer to an audio source (maybe a squeaky door or leaky faucet) the louder it will be. The further we are from it, the fainter it is.
How can we use the Google VR spacial audio plugin?
First we need to enable the plugin. Enable the plugin by going to Edit > Project Settings > Audio. In the Spacializer Plugin, select GVR Audio Spacializer.
Add the GVR Audio Listener to the main camera.
Add the GVR Audio Source to objects you want to make noise. Assign an audio clip to the Audio Source by clicking and dragging the audio clip from the project window to the AudioClip property on the GvrAudioSource.
Tip: You can use Unity’s built in audio components in place of the GVR Spacial Audio. Instead of a GvrAudioListener, you can use AudioListener, and instead of GvrAudioSource, you can use AudioSource.
How can I setup an object to be interactable with the reticle?
Add an Event Trigger component on the object. Add a Pointer Click event. Click the plus sign. Then drag the object with the script you want to call into the object reference. Click on the function drop down to select the method you want to call with the event trigger.
Tip: Ensure there’s also a collider on the object. Without it, the event system won’t be able to interact with it.
What type of raycaster is needed to make the camera interact with 3D objects?
A physics raycaster is needed. If we’re using Google’s VR sdk, we’ll use their version of it, called GvrPhysicsRaycster.
How can we use our reticle to provide feedback for our users?
There are a couple of ways we can use our reticle to provide feedback or let our users know that something will happen or has happened. For example:
- We can use a PointerClick event that creates a click sound effect to let users know they’ve successfully clicked an object.
- We can use a PointerEnter event that will change the color of an object when the reticle hovers over an item.
- We can pair a PointerExit event to change the object’s color back to the original one
How would we get the AudioSource via a script that’s attached to the same object?
We’d use the GetComponent<>() method. This method will return a component attached to a game object. For example, if we had a game object called block, we could call block.GetComponent
Tip: We can also use this to get access to any component on an object. For example, if we have a rigidbody or collider, we can use the GetComponent<>() method for those as well: GetComponent
() or GetComponent ().